# urlz to base64 //  base64 to html.js.template 
#http://tinyurl.com/jsbase64 http://tinyurl.com/jq112


import time
import urllib2 as u2
import base64 

def fnUrlToStrB2(sIn): 
 # sIn=url.b64  out=base64.html.js v2010.sept str.to.str

 sIn =  base64.decodestring(sIn)

 #sIn = sIn.replace("zz@","") # avoid some.gfw
 stemp="""
<div class="math">%s</div>
 <script src="http://jqueryjs.googlecode.com/files/jquery-1.1.2.pack.js"  type="text/javascript"> </script>
 <script src="http://datatest314.googlecode.com/hg/hxy.base.js"  type="text/javascript"> </script>
 

 <script  type="text/javascript">
 
f2 = function  () {     $(".math").each( f1 );  } 
f1 = function  () { 
    $(this).html( fs (this.innerHTML) );  //sIn.to.sOut change.innerHTML
    }  

fs = function(sIn){
  return  Base64.decode(sIn) +" after.base64";
 }
 
 
 // main pass.document
 $().ready(f2 ) ;
 </script>
"""

 su = sIn # " http://us.mobile.reuters.com/article/topNews/idUSTRE67O4WF20100910 "
 f = u2.urlopen(su)

 s1 = f.read(909901).lower().replace( "http://","httpZZ://" ) 
 # not.connect.out "<"," @L "
 s1 = " <br> v2 s1.len = "+ su+" "+str(len(s1))   +" t= "+str(time.time())+s1
 s2 = base64.encodestring(s1) # output

 return stemp %(s2)

def reverse(s):
 t = [] 
 for x in s:
  t.append(x)
 t.reverse()
 
 return "".join(t)
 
######

#s1= base64.encodestring("http://wap.baidu.com")
#print fnUrlToStrB2(s1) # b64.in b64.out
#print reverse("aabb")










